
package com.shop.cloud.mall.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cloud.mall.common.entity.DistributionUser;
import com.shop.cloud.mall.admin.mapper.DistributionUserMapper;
import com.shop.cloud.mall.admin.service.DistributionUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * 分销员
 *
 * @author
 * @date 2021-04-25 17:40:35
 */
@Service
public class DistributionUserServiceImpl extends ServiceImpl<DistributionUserMapper, DistributionUser> implements DistributionUserService {

	@Override
	public IPage<DistributionUser> page1(IPage<DistributionUser> page, DistributionUser distributionUser) {
		return baseMapper.selectPage1(page, distributionUser);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateCommissionWithdrawal(String userId, BigDecimal commission) {
		baseMapper.update(new DistributionUser(), Wrappers.<DistributionUser>lambdaUpdate()
				.eq(DistributionUser::getUserId, userId)
				.setSql(" commission_withdrawal = commission_withdrawal + " + commission));
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateCommissionTotal(String userId, BigDecimal commission) {
		baseMapper.update(new DistributionUser(), Wrappers.<DistributionUser>lambdaUpdate()
				.eq(DistributionUser::getUserId, userId)
				.setSql(" commission_total = commission_total + " + commission));
	}
}
